package com.weimei.conversionTreasure.viewModel;

import android.os.Bundle;
import android.view.View;

import androidx.databinding.ObservableArrayList;
import androidx.databinding.ObservableField;
import androidx.databinding.ObservableInt;
import androidx.databinding.ObservableList;

import com.weimei.conversionTreasure.activity.JxsDetailActivity;
import com.weimei.conversionTreasure.activity.KhDetailActivity;
import com.weimei.conversionTreasure.http.entity.CustomListBean;

import me.goldze.mvvmhabit.base.ItemViewModel;
import me.goldze.mvvmhabit.binding.command.BindingAction;
import me.goldze.mvvmhabit.binding.command.BindingCommand;
import me.tatarka.bindingcollectionadapter2.ItemBinding;

public class KhItemVM extends ItemViewModel {

    public ObservableField<CustomListBean.DataDTO> jxsEntity = new ObservableField<>();
    public ObservableField<CustomListBean.DataDTO> khEntity = new ObservableField<>();
    public ObservableField<String> flag = new ObservableField<>();

    public ObservableField<CustomListBean.DataDTO.TradeListDTO> jyEntity = new ObservableField<>();

    public ObservableInt showJy = new ObservableInt(View.GONE);


    KhRecordVM mKhRecordVM;
    public KhItemVM(KhRecordVM viewHolder) {
        super(viewHolder);
        mKhRecordVM = viewHolder;
    }

    public void setJxsData(CustomListBean.DataDTO jsxData) {
        jxsEntity.set(jsxData);
        if (jsxData.getTradeList().size() > 0){
            showJy.set(View.VISIBLE);
            jyEntity.set(jsxData.getTradeList().get(jsxData.getTradeList().size()-1));
        }else {
            showJy.set(View.GONE);
        }
    }

    public void setKhData(CustomListBean.DataDTO khData) {
        khEntity.set(khData);
        if (khData.getTradeList().size() > 0){
            showJy.set(View.VISIBLE);
            jyEntity.set(khData.getTradeList().get(khData.getTradeList().size()-1));
        }else {
            showJy.set(View.GONE);
        }
    }

    public void setFlag(String fl) {
        flag.set(fl);
    }

    public BindingCommand itemClick = new BindingCommand(new BindingAction() {
        @Override
        public void call() {
            if (flag.get().equals("0")){
                //经销商
                Bundle bundle = new Bundle();
                bundle.putString("id",jxsEntity.get().getId()+"");
                viewModel.startActivity(JxsDetailActivity.class,bundle);
            }else {
                Bundle bundle = new Bundle();
                bundle.putString("id",khEntity.get().getId()+"");
                viewModel.startActivity(KhDetailActivity.class,bundle);
            }
        }
    });

    public BindingCommand itemLongClick = new BindingCommand(new BindingAction() {
        @Override
        public void call() {
            if (flag.get().equals("0")){
                //经销商
                mKhRecordVM.delData(jxsEntity.get().getId());
            }else {
                mKhRecordVM.delData(khEntity.get().getId());
            }
        }
    });


}
